﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MB.Orm.DB;
using MB.RuleBase.Common;
using Model;
using Public.DataAccess;

namespace Business.Service
{
    public class BDCThirdInfo
    {
        public BDCThirdInfo() { }
        /// <summary>
        /// 获取第三方信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="total"></param>
        /// <param name="parValues"></param>
        /// <returns></returns>
        public List<DCThirdInfo> GetDCThirdInfo(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<DCThirdInfo> lstDCThirdInfo = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<DCThirdInfo>
                                                ("DCThird", "GetDCThirdInfo", pageIndex, pageSize, out total, parValues);
                return lstDCThirdInfo;
            }
        }
        /// <summary>
        /// 查询第三方名称是否存在
        /// </summary>
        /// <param name="ThirdName"></param>
        /// <returns></returns>
        public List<DCThirdInfo> GetDCThirdInfoByName(string ThirdName)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<DCThirdInfo> lstDCThirdInfo = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<DCThirdInfo>("DCThird", "GetDCThirdInfoByName", ThirdName);
                return lstDCThirdInfo;
            }
        }
        /// <summary>
        /// 新增修改第三方信息
        /// </summary>
        /// <param name="DCThirdInfo"></param>
        /// <returns></returns>
        public int MergeDCThirdInfo(DCThirdInfo DCThirdInfo)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<DCThirdInfo>("DCThird", "MergeDCThirdInfo", DCThirdInfo);
        }

        public List<DCThirdInventory> GetDCThirdInventory(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<DCThirdInventory> lstDCThirdInfo = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<DCThirdInventory>
                                                ("DCThird", "GetDCThirdInventory", pageIndex, pageSize, out total, parValues);
                return lstDCThirdInfo;
            }
        }
        public List<DCThirdInventory> GetDCThirdInventoryByThirdID(int ThirdID)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<DCThirdInventory> lstDCThirdInfo = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<DCThirdInventory>("DCThird", "GetDCThirdInventoryByThirdID", ThirdID);
                return lstDCThirdInfo;
            }
        }
        public int MergeDCThirdInventory(DCThirdInventory _DCThirdInventory)
        {
            return DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQueryByEntity<DCThirdInventory>("DCThird", "MergeDCThirdInventory", _DCThirdInventory);
        }



        /// <summary>
        /// 获取第三方信息
        /// </summary>
        /// <param name="seedType"></param>
        /// <returns></returns>
        public List<DCThirdInfo> GetDCThirdInfoByComboBox(string defaultValue)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<DCThirdInfo> lmSeedlist = DatabaseExcuteByXmlHelper.NewInstance.GetObjectsByXml<DCThirdInfo>("DCThird", "GetDCThirdInfo");
                if (defaultValue != null && defaultValue != "")
                {
                    lmSeedlist.Add(new DCThirdInfo() { THIRDID = 0, THIRDNAME = defaultValue });

                }
                return lmSeedlist;
            }
        }
    }
}
